######################################################################
# Time-stamp: <05/04/22 14:59:10 ostolop>
######################################################################
package EP::EPC::Core::User_Preferences;

use strict;

use EP::Common;
use EP::Common::DB;
use EP::Common::Error qw ( :try );
use EP::Common::General;

use EP::EPC::Core::Component;

use Carp;
use Carp qw (cluck);

our @ISA = qw ( EP::EPC::Core::Component );

sub process_component {
  my $self = shift;
  my $process_result;

  if ( $self->{current_user}->id == 1 ) { die "Guest user cannot change preferences" ; }
  $self->process_user_preferences ();

  $process_result = {};

  $self->{CD}->{process_result} = $process_result;
  return OK;
}

sub process_user_preferences {
  my $self = shift;

  my $query = $self->{query};
  my $user  = $self->{current_user};

  $self->{session}->status ( "Saving preferences ..." );

  $user->user_level ( $query->param ( "user_level" ) );
  $user->visualization_format ( $query->param ( "visualization_format" ) );
  $user->show_analysis_history ( $query->param ( "show_analysis_history" ) );
  $user->show_context_help ( $query->param ( "show_context_help" ) );

  $user->update;
}

1;
